package com.gxa.modules.service.impl;

import com.gxa.common.constants.Constants;
import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.R;
import com.gxa.modules.mapper.WaybillAbnormalMapper;
import com.gxa.modules.pojo.CustComplian;
import com.gxa.modules.pojo.WaybillAbnormal;
import com.gxa.modules.service.Waybill_abnormalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class Waybill_abnormalServiceimpl implements Waybill_abnormalService {
    @Autowired
    private WaybillAbnormalMapper waybillAbnormalMapper;
    JsonResult jsonResult = new JsonResult();
    R r = new R();

    /**
     * 分页查询运单异常
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public JsonResult findWaybill_abnormal(Integer currentPage, Integer pageSize) {
        int count = waybillAbnormalMapper.findCountWaybill(Constants.STATUS_UNDEL);
        Integer start = (currentPage-1)*pageSize;
        Integer off = pageSize;
        List<Map> result = waybillAbnormalMapper.findWaybillAbnormal(start, off, Constants.STATUS_UNDEL);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        jsonResult.setCount(count);
        jsonResult.setData(result);
        return jsonResult;

    }

    /**
     * 增加运单异常
     * @param waybillAbnormal
     * @return
     */
    @Override
    public R addWaybill_abnormal(WaybillAbnormal waybillAbnormal) {
        int i = waybillAbnormalMapper.addWaybillAbnormal(waybillAbnormal);
        if (i>0){
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;
    }

    /**
     * 删除运单异常
     * @param id
     * @return
     */
    @Override
    public R deleteWaybill_abnormal(Integer id) {
        int i = waybillAbnormalMapper.deleteWaybillAbnormal(id, Constants.STATUS_DEL);
        if (i>0){
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }

    /**
     * 批量删除运单异常
     * @param ids
     * @return
     */
    @Override
    public R deleteWaybill_abnormalList(int[] ids) {
        int i = waybillAbnormalMapper.deleteWaybillAbnormalList(ids, Constants.STATUS_DEL);
        if (i>0){
            r.setCode(200);
            r.setMsg("批量删除成功");
        }
        return r;
    }

    /**
     * 修改运单异常
     * @param waybillAbnormal
     * @return
     */
    @Override
    public R updateWaybill_abnormal(WaybillAbnormal waybillAbnormal) {
        int i = waybillAbnormalMapper.updateWaybillAbnormal(waybillAbnormal);
        if (i>0){
            r.setCode(200);
            r.setMsg("修改成功");
        }
        return r;
    }

    /**
     * 查看运单异常
     * @param id
     * @return
     */
    @Override
    public JsonResult seeWaybill_abnormal(Integer id) {
        List<CustComplian> custComplians = waybillAbnormalMapper.seeWaybillAbnormal(id);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        jsonResult.setData(custComplians);
        return jsonResult;
    }

    /**
     * 添加处理
     * @param id
     * @param deal_note
     * @param deal_time
     * @return
     */
    @Override
    public R dealWaybill_abnormal(Integer id, String deal_note, String deal_time) {
        int i = waybillAbnormalMapper.dealWaybillAbnormal(id, deal_note, deal_time);
        if (i>0){
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;
    }

    /**
     * 添加完结
     * @param id
     * @param end_note
     * @param end_time
     * @return
     */
    @Override
    public R endWaybill_abnormal(Integer id, String end_note, String end_time) {
        int i = waybillAbnormalMapper.endWaybillAbnormal(id, end_note, end_time);
        if (i>0){
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;
    }

    @Override
    public JsonResult searchWaybill_abnormal(String waybill_id, Integer abnor_link, Integer type, String time) {
        List<Map> maps = waybillAbnormalMapper.searchWaybillAbnormal(waybill_id, abnor_link, type, time, Constants.STATUS_UNDEL);
        jsonResult.setMsg("查询成功");
        jsonResult.setData(maps);
        return jsonResult;
    }


}
